1. Field of the Invention
The present invention is directed toward the field of object oriented software systems, and more particularly to memory allocation of instances of objects.
2. Art Background
An object oriented approach to programming provides many advantages over traditional procedural programming approaches. For example, an object oriented approach permits code reuse through inheritance and modularity through encapsulation. There are many views as to what concepts define object oriented programming, and there are many terms and definitions for defining these concepts. In general, objects incorporate procedures, also called methods or operations, and data, also called attributes or properties. Objects are instantiated from and described by structures known as classes or types. A type or class is a general abstract specification, and an object instantiated from a type is a specific concrete instance of the type.
A type consists of an interface and an implementation. The interface comprises variables and function declarations, wherein the variables represent the attributes of the type, and the function declarations specify methods for manipulating those attributes as well as performing other operations. The declaration specifies the name, return type, and argument, known collectively as the signature. The implementation refers to the actual code that implements the methods specified in the interface. Types may consist of abstract types or implementation types. Objects are not instantiated from abstract types. Instead, objects are instantiated from an implementation type.
In general, objects communicate through message passing mechanisms. An object, known as a client object, may call a method of another object. A client object invokes a method of another object by accessing the object via the defined interfaces. Thus, to invoke a method in an object or to query an object, the client object requires knowledge of the signatures of the methods in the interface of the target object. The client object calls the methods and passes the appropriate parameters. For example, to obtain the value of an attribute in an object, a client object calls a method, via an interface, to obtain the value.
Object instances, instantiated from implementation types or classes, are used for the execution of programs. Many instances of an object may be instantiated from an implementation type during execution of a program. The creation and deletion of object instances during program execution is referred to as xe2x80x9cobject life cycle.xe2x80x9d Object life cycle management becomes very complex in large programs because thousands of object instances may be created and deleted throughout the execution of the program.
Object life cycle management includes requesting memory blocks to create object instances, and relinquishing memory blocks to delete object instances. Specifically, for each instance of an object created, memory is allocated for that instance. At the end of the object""s life cycle, the object instance is deleted, and its memory block is released or freed for subsequent reuse. The generation of an object instance thus requires using memory management resources for allocation of a memory block to store the object instance in system memory. Similarly, the deletion of an object instance consumes memory management resources by requiring re-allocation of memory freed as a result of deleting the object instance. Thus, effective object life cycle management should include some form of memory management to efficiently manage memory allocation during creation and deletion of object instances.
In general, memory management includes dynamic allocation of memory resources to software programs resident in the computer system memory. Typically, dynamic memory management consists of allocating sections of memory, in response to requests from the software programs, and managing free memory blocks. Dynamic allocation of memory, or dynamic memory, is memory requested by software programs during operation of the software programs. Typically, software programs require low level routines for management of dynamic memory. Dynamic memory allocation is typically required because an application program cannot be pre-configured with memory that fulfills all possible run time requirements of the application. For example, the number of object instances for any object is not known prior to execution of the program. Thus, statically allocating all memory requirements for each object instance is not possible nor efficient. As part of the object""s life cycle, object instances are deleted after they are no longer needed in the program. However, it is difficult to ascertain the end of the life cycle for an object instance, and thus determine when memory for the object instance may be available for system memory use.
As discussed above, many object instances may be instantiated from a single implementation type or class during execution of a software program. In fact, for a commonly used object, such as a text buffer object used to temporarily store text strings, hundreds or even thousands of instances of the object may be generated during execution of a program. For the text buffer object example, many objects in a program may instantiate instances of the text buffer object, for use as a temporary buffer, and then shortly thereafter delete the instance when the buffer is no longer needed. For this example, thousands of object instances may be instantiated, and shortly thereafter deleted. Accordingly, for the text buffer object example, a significant amount of memory management resources may be consumed to create and delete the object instances. Thus, it is desirable to minimize the amount of memory management resources used in object life cycle management to enhance overall system performance.
An object instance memory allocation module allocates blocks of memory in an object oriented software system. The object instance memory allocation module includes an object instance pool for each reusable object class. The object instance pool contains a plurality of entries, and each entry is associated with a memory block configured to store an object instance for the object class. When an object instance is instantiated from an object class, the object instance memory allocation module allocates, from an entry of the object instance pool, a memory block if one of the memory blocks are available. When an object instance is released (i.e., deleted), the object instance memory allocation module re-assigns memory blocks for the object class into an entry of the object instance pool.